const mysql = require('../config/db')
const { DataTypes } = require('sequelize')
require('dotenv').config()

const Message = mysql.define(
  'message',
  {
    id: {
      type: DataTypes.BIGINT,
      primaryKey: true,
      autoIncrement: true,
    },
    content: {
      type: DataTypes.STRING({
        length: 500,
      }),
      allowNull: false,
    },
    name: {
      type: DataTypes.STRING({
        length: 20,
      }),
      allowNull: false,
    },
    title: {
      type: DataTypes.STRING({
        length: 20,
      }),
      allowNull: false,
    },
    email: {
      type: DataTypes.STRING({
        length: 50,
      }),
      allowNull: false,
    },
    createdAt: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW,
    },
    updatedAt: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW,
    },
  },
  {
    tableName: 'message',
    paranoid: true,
    deletedAt: process.env.DELETED_AT,
    timestamps: true,
    updatedAt: 'updatedAt',
    createdAt: 'createdAt',
  },
)

module.exports = Message
